<script setup>
import { ElConfigProvider } from 'element-plus'
import { computed } from 'vue'
import { useRoute } from 'vue-router'

// 获取当前路由
const route = useRoute()

// 定义全屏页面路径(不显示侧边栏)
const fullscreenRoutes = [
  '/login'
]

// 判断是否显示侧边栏
const showSidebar = computed(() => {
  return !fullscreenRoutes.includes(route.path)
})
</script>

<template>
  <el-config-provider :locale="zhCn">
    <div id="app">
      <!-- 只在非全屏页面显示侧边栏 -->
      <Sidebar v-if="showSidebar" @sidebar-toggle="handleSidebarToggle" />
      <div class="main-content" :class="{ 'fullscreen': !showSidebar, 'sidebar-collapsed': isSidebarCollapsed }">
        <div class="main-content" :class="{'sidebar-collapsed': isSidebarCollapsed}">
          <router-view />
        </div>
      </div>
    </div>
  </el-config-provider>
</template>

<script>
import Sidebar from './layouts/Sidebar.vue'

export default {
  components: { Sidebar },
  data() {
    return {
      isSidebarCollapsed: false
    }
  },
  methods: {
    handleSidebarToggle(collapsed) {
      this.isSidebarCollapsed = collapsed;
    }
  }
}
</script>

<style>
html, body, #app {
  height: 100%;
  margin: 0;
}

#app {
  display: flex;
}

.main-content {
  flex: 1;
}

.main-content.fullscreen {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
</style>

